{{define "Title"}}{{.package.Title}}{{end}}
{{define "ContentWidth"}}8{{end}}
{{define "Breadcrumb"}}
{{$package := .utils.AssertPackage .package}}
{{$category := $package.Category .db}}
<ul class="breadcrumb">
  <li><a href="/"><i class="glyphicon glyphicon-home"></i> 首页</a></li>
  <li><a href="/packages">第三方包</a></li>
  <li><a href="/packages/{{$category.Id}}">{{$category.Name}}</a></li>
  <li class="active">{{.package.Title}}</li>
</ul>
{{end}}
{{define "Content"}}
{{$package := .utils.AssertPackage .package}}
{{$category := $package.Category .db}}
<div class="content">
  <div class="page-header">
	<h1>{{.package.Title}}</h1>
	{{if .username}}
	{{$package := .utils.AssertPackage .package}}
	{{if $package.CanEdit .username .db}}
	<div class="btn-group btn-group-sm pull-right" role="group">
      <a href="/p/{{.package.Id_.Hex}}/delete" class="btn btn-default" title="删除"><i class="glyphicon glyphicon-remove"></i></a>
	  <a href="/p/{{.package.Id_.Hex}}/edit" class="btn btn-default" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
	</div>
	{{end}}
	{{end}}
	{{.shareCode}}
	<div class="clearfix"></div>
  </div>
  <div class="body editormd-preview-container">
	{{.package.Html}}
  </div>
  <hr>
  <ul>
	<li><strong>类别：</strong><a href="/packages/{{$category.Id}}">{{$category.Name}}</a></li>
	<li><strong>URL：</strong><a href="{{.package.Url}}" target="_blank">{{.package.Url}}</a></li>
	<li><strong>收录时间：</strong>{{formattime .package.CreatedAt}}</li>
  </ul>
</div>
{{$package := .utils.AssertPackage .package}}
<div id="replies" class="content editormd-preview-container">
  <span>{{.package.CommentCount}} 回复</span>
  <hr>
  <dl class="replies">
	{{range $index, $reply := $package.Comments .db}}
	{{$commenter := .Creater $.db}}
	<dd id="{{.Id_.Hex}}">
	  <span class="label label-default pull-right">#{{add $index 1}}</span>
	  {{if $.username}}
	  {{if $reply.CanDeleteOrEdit $.username $.db}}
	  <!--
	  <div class="btn-group btn-group-xs pull-right" style="margin-right: 1em;">
		<a href="javascript:;" class="edit-comment btn btn-default" title="编辑" comment-id="54d8ca7b764cf00daf000002"><i class="glyphicon glyphicon-edit"></i></a>
		<a href="/comment/54d8ca7b764cf00daf000002/delete" class="btn btn-default" title="删除" onclick="return confirm('确认删除该评论吗？');"><i class="glyphicon glyphicon-remove"></i></a>
	  </div>-->
	  {{end}}
	  {{end}}
	  <a href="/" class="pull-left" style="margin-right: 10px;"><img src="{{$commenter.AvatarImgSrc 48}}" class="img-rounded"></a>
	  <div class="info">
		<a href="/member/{{$commenter.Username}}"><strong>{{$commenter.Username}}</strong></a> •
		{{formattime .CreatedAt}}
	  </div>
	  <div class="space"></div>
	  <div class="reply-content">{{.Html}}</div>
	  <div class="clear"></div>
	</dd>
	{{end}}
  </dl>
</div>

{{if .username}}
<div id="reply">
  <form action="/comment/{{$package.Id_.Hex}}" method="post" class="form-vertical" id="reply-form" role="form">
    <fieldset>
      <div class="form-group">
        <label>新回复</label>
        <div class="editormd">
          <textarea style="display: none;"></textarea>
        </div>
      </div>
      <input type="submit" class="btn btn-primary" value="回复" id="submit" disabled>
    </fieldset>
  </form>
</div>
<script>
  var editor;
  
  $(function () {
    $('#submit').attr('disabled', true);
    
    editor = createEditorMd("editormd", "#submit");
  });
</script>
{{else}}
<div class="content" style="padding: 2em;">
  需要 <a href="/signin" class="btn btn-primary">登录</a> 后方可回复, 如果你还没有账号你可以 <a href="/signup" class="btn btn-danger">注册</a> 一个帐号。
</div>
{{end}}
{{end}}

{{define "LeftSide"}}
{{end}}

{{define "RightSide"}}
<div class="col-md-4">
  <a href="/package/new" class="btn btn-primary btn-lg btn-block" style="margin-bottom: 20px;">提交第三方包</a>
  <div class="well sidebar-nav">
	<h4><small>分类</small></h4>
	<ul class="nav">
	  {{range .categories}}
	  <li><a href="/packages/{{.Id}}">{{.Name}}<span class="badge pull-right">{{.PackageCount}}</span></a></li>
	  {{end}}
	</ul>
  </div>
</div>
{{end}}
